//
//  SAIToolboxItemView.swift
//  SAC
//
//  Created by SAGESSE on 9/15/16.
//  Copyright © 2016-2017 SAGESSE. All rights reserved.
//

import UIKit

internal class SAIToolboxItemView: UICollectionViewCell {
    
    var item: SAIToolboxItem? {
        didSet {
            _titleLabel.text = item?.name
            _iconView.image = item?.image
            _iconView.highlightedImage = item?.highlightedImage
        }
    }
    
    weak var handler: AnyObject?
    
    private func _init() {
        
        self.backgroundColor = UIColor.clear
        _titleLabel.font = UIFont.systemFont(ofSize: 12)
        _titleLabel.textColor = .gray
        _titleLabel.textAlignment = .center
        _titleLabel.translatesAutoresizingMaskIntoConstraints = false
        
        _iconView.contentMode = .scaleAspectFit
        _iconView.translatesAutoresizingMaskIntoConstraints = false
        
//        let view = UIView()
//        view.backgroundColor = UIColor(white: 0, alpha: 0.2)
//        view.layer.cornerRadius = 4
//        selectedBackgroundView = view
        
        
        contentView.addSubview(_iconView)
        contentView.addSubview(_titleLabel)

        _iconView.snp.makeConstraints { (make) in
            make.centerX.equalTo(_titleLabel.snp.centerX)
            make.top.equalTo(self.snp.top).offset(0)
            make.width.equalTo(60)
            make.height.equalTo(60)
        }
        _titleLabel.snp.makeConstraints { (make) in
            make.top.equalTo(_iconView.snp_bottom).offset(2)
            make.left.right.equalToSuperview()
            make.height.equalTo(18)
        }
    }
    
    private lazy var _iconView: UIImageView = UIImageView()
    private lazy var _titleLabel: UILabel = UILabel()
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        _init()
    }
    required init?(coder aDecoder: NSCoder) {
        super.init(coder: aDecoder)
        _init()
    }
}

